module.exports = {
	createNew: createNew,
	getPayment: getPayment
};

var db = require('../common/database/db');
var http = require('http');
var idHelper = require('../common/utils/id-helper');
function createNew(data, cb) {
	db.queryWithParam('INSERT INTO member_verify_code (id,expired_time,member_id,store_id,verify_code) VALUES(?,?,?,?,?)',
		[data.id, data.expired_time, data.member_id, data.store_id, data.verify_code], cb)

}

function getPayment(code, storeId, memberId, cb) {
	db.queryWithParamSingle("SELECT * FROM member_verify_code mvc  WHERE mvc.STATUS='paid' " +
	"AND mvc.verify_code=? AND mvc.store_id=? AND mvc.member_id=?", [code, storeId, memberId], function (err, code) {
		if (err) {
			return cb(err);
		}
		if (!code) {
			return cb(err, code);
		}
		code.extended = JSON.parse(code.extended);
		cb(err, code);
	});

	//db.queryWithParamSingle("SELECT op.* FROM member_verify_code mvc " +
	//"LEFT JOIN orderpayments op ON op.id=mvc.payment_id WHERE mvc.STATUS='paid' " +
	//"AND mvc.verify_code=? AND mvc.store_id=? AND mvc.member_id=?", [code, storeId, memberId], function (err, orderPayment) {
	//	if (err) {
	//		return cb(err);
	//	}
	//	if (!orderPayment) {
	//		return cb(err, orderPayment);
	//	}
	//	db.queryWithParamSingle("SELECT o.* FROM checkout_orderpayments cop LEFT JOIN orders o ON o.checkout_id=cop.checkout_id " +
	//	"WHERE cop.payments_id=?", [orderPayment.id], function (err, data) {
	//		if (err) {
	//			return cb(err);
	//		}
	//		orderPayment.orderInfo = data;
	//		cb(err, orderPayment);
	//	});
	//});
}

